interface HttpManagerCallback
{
    getDataSucceed();
    getDataFailed();
}
class HttpManager
{
	private static s_HttpManager:HttpManager;
	public static getInstance():HttpManager
	{
		if(this.s_HttpManager == null)
		{
			this.s_HttpManager = new HttpManager();
		}
		return this.s_HttpManager;
	}
	private m_HttpRequest:HttpRequest;
	public init(url:string)
	{
		this.m_HttpRequest = new HttpRequest();
		this.m_HttpRequest.setDataUrl(url);
	}
    public getAllData(callback:HttpManagerCallback)
    {
        this.m_HttpRequest.getAllData(callback);
    }
}

class HttpRequest
{
    private m_DataURL:string;
	public setDataUrl(url:string)
	{
		this.m_DataURL = url;
	}
    public getAllData(callback:HttpManagerCallback)
    {
        this.getConfigData(callback);
    }
    public downLoadAllResource(callback:HttpManagerCallback)
    {

    }
	private getConfigData(callback:HttpManagerCallback)
	{
		let self = this;
        class Callback implements HttpDataCallback
        {
            public dealProgress(event:egret.ProgressEvent)
            {
                //console.log("get progress : " + Math.floor(100*event.bytesLoaded/event.bytesTotal) + "%");
            }
            public dealSuccess(event:egret.Event)
            {
                var request = <egret.HttpRequest>event.currentTarget;
                console.log("get data : ",request.response);
                var jsonObj = JSON.parse(request.response);
                DataManager.getInstance().m_httpData = jsonObj;
            }
            public dealFail(event:egret.IOErrorEvent)
            {
                console.log("fail");
            }
        }
        class LayaCallback implements HttpDataLayerCallback
        {
            layerSuccess()
            {
                if(callback != null)
                {
                    callback.getDataSucceed();
                }
            }
            layerError()
            {
                if(callback != null)
                {
                    callback.getDataFailed();
                }
            }
        }
        let layCallback:LayaCallback = new LayaCallback();
        let conCallback:Callback = new Callback();
        let httpData:HttpData = HttpData.create(this.m_DataURL, HttpDataMethod.GET, "", 1000, conCallback);
        HttpConnector.getInstance().getLayer("0").setCallback(layCallback);
        HttpConnector.getInstance().getLayer("0").addToQueue(httpData);
	}
}